package twentyThreePattern.StructuralPattern7.proxy.DynamicProxy.section2;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class MyInvocationHandler implements InvocationHandler {

	Object target = null;

	public MyInvocationHandler(Object obj) {
		this.target = obj;
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		// 设置返回值
		Object result = null;
		// 前置通知
		this.before();
		// 执行被代理的方法
		result = method.invoke(this.target, args);
		// 后置通知
		this.after();

		// 返回值
		return result;
	}

	// 前置通知
	public void before() {
		System.out.println("执行before方法");
	}

	// 后置通知
	public void after() {
		System.out.println("执行after方法");
	}

}
